<template>
	<view class="content">
		<view class="title">
			新资金密码
		</view>
		<view class="inputbox">
			<input type="password" v-model="trade_password" placeholder="请输入新资金密码" />
		</view>
		
		<view class="title">
			确认密码
		</view>
		<view class="inputbox">
			<input type="password" v-model="confirm_trade_password" placeholder="请再次确认新资金密码" />
		</view>
		<view class="title">
			短信验证码
		</view>
		<view class="inputbox">
			<input type="number" v-model="sms_code" placeholder="短信验证码" />
			<view v-show="!yan" @click="sendsms" class="minibtn">获取验证码</view>
			<view v-show="yan" class="minibtn1">{{second}}s</view>
		</view>
		<view class="zhuyi">
			*修改资金密码24小时内不可提现
		</view>
		<view class="mybtn" @click="make">
			确认
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				yan:false,
				second:60,
				confirm_trade_password:'',
				sms_code:'',
				trade_password:'',
			}
		},
		onLoad() {

		},
		methods: {
			sendsms(){
				var token =uni.getStorageSync('token')
				if(token==''||token==null){
					uni.reLaunch({
					    url:'../login/login'
					})
				}else{
					if(this.yan ){
						return false
					}
					this.yan = true
					console.log('1111111111111')
					this.http({
						url:'/api/Page/sendsms',
						method:'POST',
						header:{
							'token':token
						},
						success:res=>{
							console.log(res)
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
							let interval = setInterval(() => {
							        --this.second
							    }, 1000)
							setTimeout(() =>{
								 clearInterval(interval)
								 this.second =60
								 this.yan = false
							}, 60000);
						},
						fail:err =>{
						  	uni.showToast({
						  		title:res.data.msg,
						  		icon:'none'
						  	})
						},	
					})
				} 
				
			},
			make(){
				if(this.trade_password !=''&&this.confirm_trade_password !=''&&this.sms_code!=''){
					var token =uni.getStorageSync('token')
					if(token==''||token==null){
						uni.reLaunch({
						    url:'../../login/login'
						})
					}else{
						this.http({
						 	url:'/api/User/setTradePassword',
						 	method:'POST',
							header:{
								'token':token
							},
							data:{
								trade_password:this.trade_password,
								confirm_trade_password:this.confirm_trade_password,
								sms_code:this.sms_code
							},
						 	success:(res)=>{
								console.log(res)
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
								setTimeout(()=>{
									uni.reLaunch({
										url:'../../login/login'
									})
								},1000)	
							},
						 	error:()=>{
						 		uni.showToast({
						 			title:"请求异常"	
						 		})
						 	},	
						 })
					} 
				}else{
					uni.showToast({
						title:'信息不能为空',
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC;
		font-weight: 500;
		color:#2b2b2b;
		padding-bottom: 50rpx;
		.title{
			width: 690rpx;
			font-size: 32rpx;
			font-weight: bold;
			text-indent: 1rem;
		}
		.zhuyi{
			width: 690rpx;
			text-indent: 1rem;
			font-size: 28rpx;
			color: #FF0000;
		}
		.inputbox{
			width: 630rpx;
			height: 98rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 2px 0px rgba(43, 43, 43, 0.18);
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			margin: 20rpx auto;
			input{
				flex: 1;
			}
			.minibtn{
				color: #0072FF;
			}
		}
		.mybtn{
			width: 690rpx;
			height: 88rpx;
			background: #0072FF;
			border-radius: 10rpx;
			text-align: center;
			margin: 30rpx auto;
			font-size: 36rpx;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 88rpx;
		}
		
	}

	
</style>
